<template>
  <el-dialog :model-value="dialogVisible" :title="index === -1 ? '添加代办':'修改代办'" width="30%" @close="close">
    <el-form>
      <el-form-item label="内容">
        <el-input v-model="form.content" />
      </el-form-item>
      <el-form-item label="时间">
        <el-date-picker v-model="form.date" type="date" placeholder="Pick a day" @change="onChange()" />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="addBtn">
          添加
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
export default {
  name: '',
  components: {},
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    form: {
      type: Object,
      default: (() => {})
    },
    index: {
      type: Number,
      default: -1
    }
  },
  data () {
    return {
      // dialogVisible: true
      // form: {
      //   content: '',
      //   date: null
      // }
    }
  },
  created () { },
  mounted () { },
  methods: {
    close () {
      this.$emit('update:dialogVisible', false)
      this.form = {
        content: '',
        date: null
      }
    },
    // 添加
    addBtn () {
      this.$emit('addList', this.form)
    },
    // 获取时间
    onChange () {
      console.log(new Date(this.form.date))
      let date = new Date(this.form.date)
      let y = date.getFullYear()
      let m = date.getMonth() + 1
      m = m < 10 ? ('0' + m) : m
      let d = date.getDate()
      d = d < 10 ? ('0' + d) : d
      const time = y + '/' + m + '/' + d
      this.form.date = time
      return this.form.date
    },
  }

}
</script>

<style scoped lang="less"></style>